<?php
class input
{
	private $_rules = array();
	private $_current_filed;
	
	public function __construct() {
		$this->_initGlobals();		
	}
	/**
	 * 对所有的全局变量进行出来
	 *
	 * 对不受保护的全局变量用usset()destroy
	 */
	private function _initGlobals() {
		$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST', '_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA','EXT','BASEPATH','DIRPATH','SELF');
		foreach(array($_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, (isset($_SESSION)) ? $_SESSION : null) as $global) {
			if(! is_array($global)) {
				if(! in_array($global,$protected)) unset($GLOBALS[$global]);
			} else {
				foreach($global as $key => $value) {
					if(! in_array($key,$protected)) unset($GLOBALS[$key]);
					if(is_array($value)) {
						foreach($value as $k =>$v) {
							if(! in_array($k,$protected)) unset($GLOBALS[$k]);
						}
					}
				}
			}
		}
	}
	//post数据处理
	public function post($value) {
		if(is_numeric($value)) {
			return filter_input(INPUT_POST,$value,FILTER_VALIDATE_INT);
		}
		
		if(is_string($value)) {
			return filter_input(INPUT_POST,$value,FILTER_SANITIZE_STRING);
		}
	}
	/**
	* 字符串的验证
	*/
	public function string($value) {
		return filter_input(INPUT_POST,$value,FILTER_SANITIZE_STRING);
	}
	
	/**
	 * 数字的验证
	 */
	public function int($value) {
		return filter_input(INPUT_POST,$value,FILTER_VALIDATE_INT);
	}
	 
	public function email($email) {
		return filter_input(INPUT_POST,$email,FILTER_VALIDATE_EMAIL);
	}
	
	public function password($value) {
		//$args = array('options'=>array('min_range'=>6,'max_range'=>16));
		//return filter_var($value,FILTER_SANITIZE_STRING,$args);
	}
	
	public function validPass($user_pass,$user_passconf) {
		return ($user_pass == $user_passconf) ? true : false;
	}	

	public function validURL($url) {
		return filter_input(INPUT_POST,$url,FILTER_VALIDATE_URL);
	}
	
	 
}
		

?>